package org.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.entity.task.Scan;
import org.example.mapper.ScanMapper;
import org.example.service.ScanService;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author 魏锴
 * @description 针对表【tb_task_scan】的数据库操作Service实现
 * @createDate 2024-01-13 18:22:52
 */
@Service
public class ScanServiceImpl extends ServiceImpl<ScanMapper, Scan>
        implements ScanService {

    @Override
    public boolean insertScan(Scan scan) {
        scan.setScanTime(new Date());//后台更新创建时间
        Date date = new Date();
        DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        scan.setVulNo(format.format(date));
        return baseMapper.insertScan(scan) && baseMapper.renewScan(scan.getMyTaskId());
    }

    @Override
    public List<Scan> getScanList(int tester) {
        return baseMapper.getScanList(tester);
    }

    public Map<Integer, List<String>> getVulnerabilityList(int tester) {
        List<Map<String, Object>> mapList = baseMapper.getVulnerabilityList(tester);
        Map<Integer, List<String>> result = new HashMap<>();//<myTaskId,List<vulNo>>
        int temp;
        for (Map<String, Object> map : mapList) {
            temp = (int) map.get("myTaskId");
            if (!result.containsKey(temp)) result.put(temp, new ArrayList<>());
            result.get(temp).add((String) map.get("vulNo"));
        }
        return result;
    }
}




